#include<stdio.h>
#include<mpi.h>
#include<stdlib.h>


int main(int argc, char **argv)
{
	int myid, numprocs;
	MPI_Group group_world, group1, group2;
	int i;
	int ranks1[10];
	int ranks2[10];
	int ranks_output[10];
		
	MPI_Init(&argc, &argv);
	
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
	
	MPI_Comm_group(MPI_COMM_WORLD, &group_world);

	for(i=0; i<numprocs-1; i++) {
		ranks1[i] = i ;
		ranks2[i] = i+1 ;
	}
	
	MPI_Group_incl(group_world, numprocs-1, ranks1, &group1);
	MPI_Group_incl(group_world, numprocs-1, ranks2, &group2);
	
	// your code here
    //检测两个不同组中相同进程的相对编号。如果属于进程组1的某个进程可以在ranks1中找到，
    //而这个进程不属于进程组2，则在ranks2中对应ranks1的位置返回值为MPI_UNDEFINED。
	MPI_Group_translate_ranks(group1, numprocs-1, ranks1, group2, ranks_output);
	// end of your code
	
	if (myid == 0) {
		for (i=0; i<numprocs-1; i++) {
			printf("The rank in group2 is: %d\n", ranks_output[i]);
		}
	}

	MPI_Finalize();
	return 0;
}